package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Food;
import com.itheima.pojo.Intervention;
import com.itheima.pojo.Member;
import com.itheima.service.FoodService;
import com.itheima.utils.DateUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RequestMapping("/food")
@RestController
public class FoodController {

    @Reference
    private FoodService foodService;

    @RequestMapping("/getAllFood")
    public Result getAllFood(){
        try {
            List<Food> foodList = foodService.finAll();
            //查询成功
            return new Result(true,MessageConstant.GET_FOOD_SUCCESS,foodList);
        } catch (Exception e) {
            e.printStackTrace();
            //查询套餐失败
            return new Result(false,MessageConstant.GET_FOOD_FAIL);
        }
    }

    @RequestMapping("/findFoodByOrderDate")
    public Result findFoodByOrderDate(String orderDate){
        try {
            Date date = DateUtils.parseString2Date(orderDate);
            List<String> list= foodService.findFoodByOrderDate(date);
            return new Result(true,"查询医生建议成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,"查询医生建议失败");
        }
    }

}
